#!/bin/bash

curDir=$(cd `dir $0`;pwd)
echo "当前脚本路径:$curDir"

testFile(){
    [ ! -e $curDir/name.txt ] && echo 'name.txt文件不存在' && exit 1
}

menu(){
    clear
    echo "######################"
    echo "#                    #"
    echo "#                    #"
    echo "#      抽奖程序      #"
    echo "#      q推出;g抽取   #"
    echo "#                    #"
    echo "#                    #"
    echo "######################"
}

testFile
num=$(cat $curDir/name.txt | wc -l )

while :
do
    menu
    read q
    case $q in
        g) 
            random=$[RANDOM%num+1]
            selectName=$(sed -n  "${random}p" $curDir/name.txt)
            echo -e "\e[31m中奖者$selectName\e[0m"
            read -t 5 a;;
        q) exit 0 ;;
        *) echo "错误的选项";;
    esac
done


